<?php

/**
 * Generic preference class. 
 *
 */
class preference {

    protected $_paging_limit;   // KEY ATTR. WITH AUTOINCREMENT
    protected $_company_name;
    protected $_company_url;

    /**
     *   @desc   CONSTRUCTOR METHOD
     */
    function __construct() {
        global $DBOBJ;
        $this->_obj = $DBOBJ;
        $this->_paging_limit = null;
        $this->_company_name = null;
        $this->_company_url = null;
    }

    /**
     *   @desc   DECONSTRUCTOR METHOD
     */
    function __destruct() {
        unset($this->_obj);
    }

    /**
     *   @desc   GETTER METHODS
     */
    public function getAll($FORMAT = 'ARRAY') {
        $dataArray = new stdClass();
        $dataArray->paging_limit = $this->getpaging_limit();
        $dataArray->company_name = $this->getcompany_name();
        $dataArray->company_url = $this->getcompany_url();
        if ($FORMAT == 'ARRAY') {
            return (array) $dataArray;
        }
        return $dataArray;
    }

    public function setAll($dataArray = array()) {
        if (count($dataArray) <= 0) {
            return;
        }
        foreach ($dataArray as $key => $value) {
            $classKey = '_' . $key;
            $this->$classKey = $value;
        }
    }

    public function getpaging_limit() {
        return $this->_paging_limit;
    }

    public function getcompany_name() {
        return $this->_company_name;
    }

    public function getcompany_url() {
        return $this->_company_url;
    }

    /**
     *   @desc   SETTER METHODS
     */
    public function setpaging_limit($paging_limit) {
        $this->_paging_limit = $paging_limit;
    }

    public function setcompany_name($company_name) {
        $this->_company_name = $company_name;
    }

    public function setcompany_url($company_url) {
        $this->_company_url = $company_url;
    }

    function select() {
        $sql = "SELECT * FROM preference";
        $row = $this->_obj->select($sql);
        if (count($row) > 0) {
            $this->_paging_limit = $row[0]['paging_limit'];
            $this->_company_name = $row[0]['company_name'];
            $this->_company_url = $row[0]['company_url'];
            return $row['0'];
        } else {
            return;
        }
    }

    /**
     *   @desc   UPDATE
     */
    function update() {
        $sql = "UPDATE `preference`
				SET `paging_limit` = '" . $this->_paging_limit . "',
				`company_name` = '" . $this->_company_name . "',
				`company_url` = '" . $this->_company_url . "'";
        $result = $this->_obj->sql_query($sql);
    }

}

?>